<template>
  <div class="news-section">
    <section class="news-tabs" v-show="propsData.params.showTabs">
      <div class="tab-bg" :style="tabStyle"></div>
      <div class="tab-topic-box">
        <div
          class="tab-item"
          v-for="(item, index) in tabs"
          @click="activeTab = index"
          :key="index"
          :class="
            activeTab == index && borderType == 'radius' ? 'active-radius' : ''
          "
          :style="{
            backgroundColor:
              activeTab == index && borderType == 'radius'
                ? propsData.params.tabItem.borderColor
                : '',
          }"
        >
          <span
            :style="activeTab == index ? propsData.params.tabItem.fontCss : ''"
            >{{ item }}</span
          >
          <div
            v-show="activeTab == index && borderType == 'line'"
            class="active"
            :style="{ backgroundColor: propsData.params.tabItem.borderColor }"
          ></div>
          <div class="item-hover">
            <div class="edit-box" @click.stop="handleNewsTabItem(index)">
              <i class="iconfont icon-mokuai-bianji"></i>
            </div>
          </div>
        </div>
        <div class="hover-box">
          <div class="edit-box" @click.stop="handleNewsTab">
            <i class="iconfont icon-mokuai-bianji"></i>
          </div>
        </div>
      </div>
    </section>
    <section class="news-card">
      <div class="news-item">
        <div class="news-info">
          <p class="title">
            「深度解读」塔利班承诺的能做到吗？街头的改变有深意。阿富汗民意究竟如何？
          </p>
          <p class="news-shows">
            <span>30分钟前</span>
            <span>2.2万阅读</span>
          </p>
        </div>
        <div class="news-banner">
          <img src="@/assets/images/diy/default_img.png" alt="" />
        </div>
      </div>
      <div class="hold-line" :style="splitLine"></div>
      <div class="news-item">
        <div class="news-info">
          <p class="title">
            「深度解读」塔利班承诺的能做到吗？街头的改变有深意。阿富汗民意究竟如何？
          </p>
          <p class="news-shows">
            <span>30分钟前</span>
            <span>2.2万阅读</span>
          </p>
        </div>
        <div class="news-banner">
          <img src="@/assets/images/diy/default_img.png" alt="" />
        </div>
      </div>
      <div class="hold-line" :style="splitLine"></div>
      <div class="news-full-line">
        <p class="title">
          「深度解读」塔利班承诺的能做到吗？街头的改变有深意。阿富汗民意究竟如何？
        </p>
        <div class="news-banner">
          <img src="@/assets/images/diy/default_img.png" alt="" />
        </div>
        <p class="news-shows">
          <span>30分钟前</span>
          <span>2.2万阅读</span>
        </p>
      </div>
    </section>
  </div>
</template>

<script>
import topicLineOne from "@/assets/images/diy/toPic/topic_line_one.png";
import topicLineTwo from "@/assets/images/diy/toPic/topic_line_two.png";

export default {
  name: "",
  props: {
    propsData: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      tabs: ["科技", "互联网", "财经", "军事", "国际", "国内", "体育", "娱乐"],
      activeTab: 0,
    };
  },
  mounted() {
    console.log(this.propsData);
  },
  watch: {},
  computed: {
    topicImg() {
      if (this.propsData.params.styleType == 1) {
        if (this.propsData.params.topPicImg)
          return this.propsData.params.topPicImg;

        if (this.propsData.params.lineNum == 1) return topicLineOne;
        if (this.propsData.params.lineNum == 2) return topicLineTwo;
      }
    },
    splitLine() {
      let style = Object.assign({}, this.propsData.params.splitLine);
      style.borderWidth = style.borderWidth + "px";
      return style;
    },
    borderType() {
      return this.propsData.params.tabItem.borderType;
    },
    tabStyle() {
      if (!this.propsData.params.tab.useBackground) return {};
      let style = Object.assign({}, this.propsData.params.tab);
      if (
        this.propsData.params.tab.backgroundColor &&
        this.propsData.params.tab.opacity
      ) {
        style.opacity = "";
      }
      return style;
    },
  },
  methods: {
    // 点击专题导航
    handleNewsTab() {
      console.log("点击了专题导航");
      let data = Object.assign({}, this.propsData);
      data.controlComName = "diyTopPicTabControl";
      this.$emit("handleNewsTab", data);
    },
    // 点击单个专题导航
    handleNewsTabItem(index) {
      console.log("点击单个专题导航");
      this.activeTab = index;
      let data = Object.assign({}, this.propsData);
      data.controlComName = "diyTopPicTabItemControl";
      this.$emit("handleNewsTabItem", data);
    },
  },
};
</script>

<style lang="scss" scoped>
.news-section {
  width: 100%;
  padding-bottom: 12px;
  .news-tabs {
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    height: 44px;
    position: relative;
    overflow: hidden;
    .tab-bg {
      width: 100%;
      height: 100%;
    }
    .tab-topic-box {
      width: 100%;
      height: 100%;
      position: absolute;
      left: 0;
      top: 0;
      display: flex;
      align-items: center;
      height: 44px;
      padding: 0 9px;
    }
    .tab-item {
      margin-right: 18px;
      flex-shrink: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      position: relative;
      z-index: 11;
      padding: 3px;
      span {
        font-size: 15px;
        font-family: PingFang SC;
        font-weight: 400;
        color: #262626;
        padding-bottom: 2px;
      }
      .active {
        width: 100%;
        height: 2px;
        background-color: #ff0000;
      }

      .item-hover {
        width: 100%;
        height: 100%;
        border: 1px solid #1890fc;
        position: absolute;
        left: 0;
        top: 0;
        display: none;
        .edit-box {
          width: 20px;
          height: 20px;
          background: #1890fc;
          border-radius: 0px 0px 0px 4px;
          display: flex;
          justify-content: center;
          align-items: center;
          cursor: pointer;
          position: absolute;
          right: 0;
          top: 0;
          .iconfont {
            font-size: 18px;
            color: #ffffff;
          }
        }
      }
    }
    .tab-item:last-child {
      margin-right: 0;
    }
    .active-radius {
      padding: 2px 8px;
      border-radius: 60px;
      background-color: #ff0000;
      span {
        padding-bottom: 0;
        font-weight: bold;
      }
    }
    .tab-item:hover > .item-hover {
      display: block;
    }
    .hover-box {
      width: 99.4%;
      height: 100%;
      border: 1px solid #1890fc;
      display: none;
      position: absolute;
      left: 0;
      top: 0;
      z-index: 1;
      .edit-box {
        width: 20px;
        height: 20px;
        background: #1890fc;
        border-radius: 0px 0px 0px 4px;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        position: absolute;
        right: 0;
        top: 0;
        .iconfont {
          font-size: 18px;
          color: #ffffff;
        }
      }
    }
  }
  .tab-topic-box:hover > .hover-box {
    display: block;
  }
  .news-card {
    padding-top: 10px;
  }
  .news-item {
    width: 100%;
    padding: 0 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .news-banner {
      width: 108px;
      height: 85px;
      background: #ebebeb;
      border-radius: 4px;
      display: flex;
      align-items: center;
      justify-content: center;
      img {
        width: 34px;
        height: 26px;
      }
    }
    .news-info {
      flex: 1;
      max-width: 220px;
      height: 85px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .title {
        font-size: 16px;
        font-family: PingFang SC;
        font-weight: 800;
        color: #000000;
        margin-bottom: 24px;
        max-width: 220px;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
      }
      .news-shows {
        margin-bottom: 0;
        font-size: 12px;
        font-family: PingFang SC;
        font-weight: 400;
        color: #999999;
        span:nth-child(1) {
          margin-right: 12px;
        }
      }
    }
  }
  .hold-line {
    width: 351px;
    height: 0px;
    border-top: 1px solid #dbdbdb;
    margin: 10px auto;
  }
  .news-full-line {
    width: 100%;
    padding: 0 12px;
    display: flex;
    flex-direction: column;
    .title {
      font-size: 16px;
      font-family: PingFang SC;
      font-weight: 800;
      color: #000000;
      margin-bottom: 11px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      max-width: 349px;
    }
    .news-banner {
      width: 100%;
      height: 180px;
      background: #ebebeb;
      border-radius: 4px;
      display: flex;
      justify-content: center;
      align-items: center;
      margin-bottom: 10px;
      img {
        width: 100px;
        height: 77px;
      }
    }
    .news-shows {
      font-size: 12px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #999999;
      span:nth-child(1) {
        margin-right: 12px;
      }
    }
  }
}
</style>
